%pngFiles = ls('thesis\*.png');
pngFiles=['precond2D.png';'precond3D.png'];
for k=1:size(pngFiles,1)
    if strfind(pngFiles(k,:),'fig1.png')
        continue
    end
    fn=['thesis\' pngFiles(k,:)];
    pic=imread(fn);
    sumpic=sum(pic,3);
    for i=1:size(sumpic,1)
        for j=1:size(sumpic,2)
            if sumpic(i,j) ~= 3*255
                break
            end
        end
        if sumpic(i,j) ~= 3*255
            break
        end
    end
    istart=i-5;
    for j=1:size(sumpic,2)
        for i=1:size(sumpic,1)
            if sumpic(i,j) ~= 3*255
                break
            end
        end
        if sumpic(i,j) ~= 3*255
            break
        end
    end
    jstart=j-5;
    for i=size(sumpic,1):-1:1
        for j=1:size(sumpic,2)
            if sumpic(i,j) ~= 3*255
                break
            end
        end
        if sumpic(i,j) ~= 3*255
            break
        end
    end
    iend=i+5;
    for j=size(sumpic,2):-1:1
        for i=1:size(sumpic,1)
            if sumpic(i,j) ~= 3*255
                break
            end
        end
        if sumpic(i,j) ~= 3*255
            break
        end
    end
    jend=j+5;
    pic1=pic(istart:iend,jstart:jend,:);
    imwrite(pic1,fn,'png');
    fprintf('done for fn = %s\n',fn);
end